package com.lilosoft.business.util;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description: precity中的Service的异常处理
 * User: 小峰
 * Date: 2019-08-30
 * Time: 15:07
 */
@Aspect
@Component
public class AopLog {
    private Logger logger = LoggerFactory.getLogger(getClass());



    // @Around(value = "execution(* com.lilosoft.business.*.service..*.*(..))")
    //public Object ServiceExceptionLog(ProceedingJoinPoint proceedingJoinPoint) {
    //    Object proceed=null;
    //    try {
    //         proceed = proceedingJoinPoint.proceed();
    //    } catch (Exception e){
    //        logger.error("执行出现异常"+e.getMessage());
    //    }
    //    catch (Throwable throwable) {
    //        throwable.printStackTrace();
    //        logger.error("执行出现异常"+throwable.getMessage());
    //    }
    //    return proceed;
    //}


    @AfterThrowing(value = "execution(* com.lilosoft.business.*.service..*.*(..))",throwing="ex")
    public void ServiceExceptionLog(JoinPoint jp, Throwable ex) {
        logger.error(jp.getTarget().getClass() + "类的方法的" +
                jp.getSignature().getName() + "可以记录程序运行时候抛出的异常信息: " +
                ex.getMessage());
    }



}
